package com.jxk.test.config;

import com.jxk.test.filter.MyFilter;
import com.jxk.test.listener.MyRequestListtener;
import com.jxk.test.listener.MyHttpSessionListener;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionListener;

/**
 * @ClassName : MywebConfig  //类名
 * @Description :   //描述
 * @Author : jxk  //作者
 * @Date: 2020-09-21 14:07  //时间
 */
@Configuration
public class MywebConfig implements WebMvcConfigurer {
    //注册监听器
    @Bean
    public ServletListenerRegistrationBean<HttpSessionListener> listenerRegist() {
        ServletListenerRegistrationBean<HttpSessionListener> srb = new ServletListenerRegistrationBean();
        srb.setListener(new MyHttpSessionListener());

        System.out.println("listener");
        return srb;
    }
    @Bean
    ServletListenerRegistrationBean<ServletRequestListener> listenerRegistrationBean(){
        ServletListenerRegistrationBean<ServletRequestListener> srb = new ServletListenerRegistrationBean();
        srb.setListener(new MyRequestListtener());
        return srb;
    }
    @Bean
    //注册
    public FilterRegistrationBean filterRegist() {
        FilterRegistrationBean frBean = new FilterRegistrationBean();
        frBean.setFilter(new MyFilter());
        frBean.addUrlPatterns("/doFilter");
        System.out.println("filter");
        return frBean;
    }

}
